package com.glsc.ngateway.opmanage.service.outsys;


import com.glsc.ngateway.common.api.common.utils.PageUtil;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.outsys.OutSystemOaLog;
import com.glsc.ngateway.common.base.repo.mysql.opmanagemain.outsys.OutSystemOaLogRepository;
import com.glsc.ngateway.opmanage.utils.SpecificationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Slf4j
public class OutSystemOaLogService {

    @Resource
    private OutSystemOaLogRepository outSystemOaLogRepository;


    public Page<OutSystemOaLog> page(int pageNo, int pageSize, Map<String, Object> param) {
        Sort.Direction direction = Sort.Direction.DESC;
        String sort = "createTime";

        pageNo = PageUtil.initPageNo(pageNo);
        pageSize = PageUtil.initPageSize(pageSize);

        Pageable pageable = PageRequest.of(pageNo - 1, pageSize, direction, sort);
        Page<OutSystemOaLog> page = outSystemOaLogRepository.findAll(SpecificationUtil.buildSpecification(param, OutSystemOaLog.class), pageable);
        return page;
    }

}
